cc.Class({
    extends: cc.Component,

    properties: {
       resultLabel:cc.Label,
       mask:cc.Mask,
       prompLabel:cc.Label,
    },

    // use this for initialization
    onLoad: function () {
        this.node.on(cc.Node.EventType.TOUCH_START,this._onTouchStart,this);
        this.node.on(cc.Node.EventType.TOUCH_MOVE,this._onTouchMove,this);
        this.node.on(cc.Node.EventType.TOUCH_END,this._onTouchEnd,this);
        this.node.on(cc.Node.EventType.TOUCH_CANCEL,this._onTouchCancel,this);
    },

    onDestroy:function () {
        this.node.off(cc.Node.EventType.TOUCH_START,this._onTouchStart,this);
        this.node.off(cc.Node.EventType.TOUCH_MOVE,this._onTouchMove,this);
        this.node.off(cc.Node.EventType.TOUCH_END,this._onTouchEnd,this);
        this.node.off(cc.Node.EventType.TOUCH_CANCEL,this._onTouchCancel,this);
        
    },
    // called every frame, uncomment this function to activate update callback
    // update: function (dt) {

    // },
    _onTouchStart:function(event){
        console.log('touchStart');
        var point = event.touch.getLocation();
        point = this.node.convertToNodeSpaceAR(point);
        this._addCircle(point);
    },
    _onTouchMove:function(event){
        console.log('touchMove');
        var point = event.touch.getLocation();
        point = this.node.convertToNodeSpaceAR(point)
        this._addCircle(point);
    },
    _onTouchEnd:function(event){
        console.log('touchEnd');
        var point = event.touch.getLocation();
        point = this.node.convertToNodeSpaceAR(point);
        this._addCircle(point);
    },
    _onTouchCancel:function(event){
        console.log('touchCancel');
    },
    _addCircle:function(point){
        var stencil = this.mask._clippingStencil;
        console.log(this.mask)
        var color = cc.color(255, 255, 255, 0);
        stencil.drawPoly(this.mask._calculateCircle(point,cc.p(50,50), 64), color, 0, color);
        if (!CC_JSB) {
            cc.renderer.childrenOrderDirty = true;
        }
    },
});
